package com.coszero.common.utils;

import android.content.Context;

import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.ItemDecoration;

import com.coszero.commonlib.R;
import com.coszero.utils.utils.DensityUtil;
import com.coszero.utils.app.AppUtils;
import com.coszero.utils.decoration.HorizontalDividerItemDecoration;
import com.coszero.utils.decoration.SpacingItemDecoration;
import com.coszero.utils.decoration.VerticalDividerItemDecoration;

/**
 * Desc： RecyclerView 分割线
 *
 * @author xmqian
 * Email:xmqian93@163.com
 * Date: 2021/8/30 0030
 * @version 2
 */
public class RecyclerDiverUtils {

    // <editor-fold desc="横向分割线" defaultstate="collapsed">

    /**
     * 横向分割线
     *
     * @param context context
     * @param color 分割线颜色
     * @param size 分割线粗细 px单位
     * @return 构造好的分割线
     */
    public static ItemDecoration hDiver(Context context, int color, int size) {
        HorizontalDividerItemDecoration horizontalDividerItemDecoration = new HorizontalDividerItemDecoration.Builder(context)
                .color(color).size(size).build();
        return horizontalDividerItemDecoration;
    }

    @Deprecated
    @SuppressWarnings({"unchecked", "deprecation"})
    public static ItemDecoration hDiver1px(Context context) {
        return hDiver(context, AppUtils.getColor(context, R.color.com_list_line), 1);
    }

    /**
     * 返回dp为单位的分割线
     *
     * @param size 单位dp
     */
    @Deprecated
    @SuppressWarnings({"unchecked", "deprecation"})
    public static ItemDecoration hDiverDp(Context context, int size) {
        return hDiver(context, AppUtils.getColor(context, R.color.com_list_line), DensityUtil.dip2px(context, size));
    }

    //</editor-fold>

    // <editor-fold desc="纵向分割线" defaultstate="collapsed">

    /**
     * 纵向分割线
     *
     * @param context context
     * @param color 分割线颜色
     * @param size 粗细 px单位
     * @return 构造好的分割线
     */
    @Deprecated
    @SuppressWarnings({"unchecked", "deprecation"})
    public static ItemDecoration vDiver(Context context, int color, int size) {
        VerticalDividerItemDecoration verticalDividerItemDecoration = new VerticalDividerItemDecoration.Builder(context)
                .color(color).size(size).build();
        return verticalDividerItemDecoration;
    }

    @Deprecated
    @SuppressWarnings({"unchecked", "deprecation"})
    public static ItemDecoration vDiver1Px(Context context) {
        return vDiver(context, AppUtils.getColor(context, R.color.com_list_line), 1);
    }

    @Deprecated
    @SuppressWarnings({"unchecked", "deprecation"})
    public static ItemDecoration vDiverDp(Context context, int size) {
        return vDiver(context, AppUtils.getColor(context, R.color.com_list_line), DensityUtil.dip2px(context, size));
    }

    //</editor-fold>

    // <editor-fold desc="空白背景分割线" defaultstate="collapsed">

    /**
     * 空白的分割线,已背景为准
     *
     * @param context context
     * @param lineSize 粗细 dp单位
     * @param spanCount 列数,根据表格列数决定
     * @return 构造好的间距
     */
    public static RecyclerView.ItemDecoration spaceDiver(Context context, int lineSize, int spanCount) {
        return new SpacingItemDecoration(spanCount, DensityUtil.dip2px(context, lineSize), false);
    }


    /**
     * 返回一列列表的分割线
     */
    @Deprecated
    @SuppressWarnings({"unchecked", "deprecation"})
    public static ItemDecoration spaceDiverH(Context context, int lineSize) {
        return spaceDiver(context, lineSize, 1);
    }

    //</editor-fold>

    @Deprecated
    @SuppressWarnings({"unchecked", "deprecation"})
    public static ItemDecoration hDiverMagin(Context context) {
        int i = DensityUtil.dip2px(context, 16);
        return new HorizontalDividerItemDecoration.Builder(context).color(AppUtils.getColor(context, R.color.com_list_line)).size(1)
                .margin(i, i).build();
    }
}
